import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import './plugins/element.js'
import './assets/css/global.css'
import './assets/fonts/iconfont.css'
import ZkTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
import echarts from 'echarts'

axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

/* 添加请求拦截器，（中间件）所有的请求都会经过这个拦截器进行预处理之后发送到服务器 */
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})

// 将echarts挂载到Vue原型上
Vue.prototype.$echarts = echarts

// 将axios挂载到Vue对象的原型上
Vue.prototype.$http = axios

// 阻止启动生产消息，常用作指令
Vue.config.productionTip = false
// 注册全局组件tree-table
Vue.component('tree-table', ZkTable)
// 全局注册一个富文本编辑器
Vue.use(VueQuillEditor)

/* 定义一个过滤器来格式化所有的时间 */
Vue.filter('dateFormat', ms => {
  const dateTime = new Date(ms)
  const year = (dateTime.getFullYear() + '').padStart(2, '0')
  const month = (dateTime.getMonth() + 1 + '').padStart(2, '0')
  const date = (dateTime.getDate() + '').padStart(2, '0')
  const hours = (dateTime.getHours() + '').padStart(2, '0')
  const minutes = (dateTime.getMinutes() + '').padStart(2, '0')
  const seconds = (dateTime.getSeconds() + '').padStart(2, '0')
  return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
